package learnJava.puzzlers;

import java.io.*;

public class IOPuzzlers {
    // 一个关闭简化关闭文件代码
    public static void close(Closeable closeable) {
        try {
            closeable.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void copy(String src,String dest) throws IOException{
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(src);
            out = new FileOutputStream(dest);
            byte[] buf = new byte[1024];
            int n;
            while ((n = in.read(buf)) >= 0) {
                out.write(buf,0,n);
            }
        }finally {
            close(in);
            close(out);
        }
    }

}
